﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using MinConsole.IniParser;
using MinConsole.Gaf.Dh;

namespace MinConsole
{
    class Program
    {
        #region IniConstants

        public const string StoredProcsToRun = "StoredProcsToRun";
        public const string DataSource = "DataSource";
        public const string DataSourcesToRun = "DataSourcesToRun";
        public const string StoredProcedure = "StoredProcedure";
        public const string StoredProc = "StoredProc";
        public const string Parameters = "Parameters"; 



        #endregion IniConstants 

        /// <summary>
        /// The starting point of the process 
        /// </summary>
        /// <param name="args"> no command line args supported </param>
        static void Main(string[] args)
        {
            #region Try 
            System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace();
            string strPathToExe = Environment.GetCommandLineArgs()[0];
            string strAppName = Path.GetFileNameWithoutExtension(strPathToExe);





            try
            {

                MinConsole.Gaf.Utils.Log.Logger.Log("START PROGRAM " + strAppName );
                MinConsole.Controller.Program objProgram = new MinConsole.Controller.Program();
                
                //objProgram.PopulateTheListOfDataSources();
                //objProgram.RunDataSources();

                //MinConsole.Gaf.Utils.Log.Logger.Log("Hit a key to exit !!! \n\n\n");   //tell the user to exit 
                //Console.ReadKey();
                MinConsole.Gaf.Utils.Log.Logger.Log("STOP PROGRAM " + strAppName);

            } //eof try

            #endregion Try

            #region Exception

            catch (Exception ex)
            {
                
                string methodName = st.GetFrame(1).GetMethod().Name;
                string className = st.GetFrame(1).GetFileName();
                int lineNumber = st.GetFrame(1).GetFileLineNumber();

                string strConsleMsg = String.Empty;
                strConsleMsg += "The following error occured during running the program " + ex.Message.ToString(); 
                strConsleMsg += "className " + className + " : " ;
                strConsleMsg += "methodName " + methodName + " : ";
                strConsleMsg += "lineNumber " + lineNumber + " ";


                #region AddHelp 
                #endregion AddHelp


                Console.Error.WriteLine(strConsleMsg); 

                //sleep for 3 seconds to give time for the reader to read the message 
                System.Threading.Thread.Sleep(6000);

                MinConsole.Gaf.Utils.Log.Logger.Log(strConsleMsg);

            } //eof catch 

            #endregion Exception

        } //eof Main

    } //eof Program 
} //eof namespace 
